package com.yipinhouse.employee.app.appImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.employee.client.WatchRecordManageClient;
import com.yipinhouse.employee.client.param.InsertWatchRecordParam;
import com.yipinhouse.employee.client.param.UpdateWatchRecordParam;
import com.yipinhouse.employee.service.WatchRecordService;
import com.yipinhouse.employee.service.param.InsertWatchRecordServiceParam;
import com.yipinhouse.employee.service.param.UpdateWatchRecordServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("watchRecord")
public class WatchRecordManageAppImpl implements WatchRecordManageClient {
    @Resource
    private WatchRecordService watchRecordService;

    @Override
    public Result insertWatchRecord(InsertWatchRecordParam insertWatchRecordParam) {
        log.info("新增看房记录的入参是"+insertWatchRecordParam);
        //TODO 从请求头取出经纪人id
        InsertWatchRecordServiceParam param = BeanUtil.copyProperties(insertWatchRecordParam, InsertWatchRecordServiceParam.class);
        param.setBrokerId(1);
        watchRecordService.insertWatchRecord(param);
        return Result.getInstance().setMsg("新增成功！").setCode(200);
    }

    @Override
    public Result updateWatchRecord(UpdateWatchRecordParam updateWatchRecordParam) {
        log.info("修改看房记录的入参是"+updateWatchRecordParam);
        //TODO 从请求头取出经纪人id
        UpdateWatchRecordServiceParam param = BeanUtil.copyProperties(updateWatchRecordParam, UpdateWatchRecordServiceParam.class);
        param.setBrokerId(3);
        watchRecordService.updateWatchRecordParam(param);
        return Result.getInstance().setMsg("修改成功！").setCode(200);
    }


}
